1. Technology Field
The present invention relates to a data management method. More particularly, the present invention relates to a data management method for accessing a flash memory, and a storage system and a controller using the same.
2. Description of Related Art
With a quick developing of digital camera, cell phone camera and MP3, demand of storage media by customers is increased greatly. Since a flash memory has the advantages of non-volatile, energy saving, small size and none mechanical structure etc., it is suitable for portable applications, and especially for portable battery-powered products. A memory card is a storage device applying an NAND flash memory as a storage medium thereof. Since the memory card has the advantages of small size, great capacity and easy to carry, it is widely applied for storage of important personal data. Therefore, the flash drive industry becomes a hot industry within the electronics industry recently.
Generally, the flash memory is divided into a plurality of physical blocks, and the physical blocks are grouped into a data area and a spare area, for example, a data area 204 and a spare area 206 shown in FIG. 1A. The physical blocks of the data area may store valid data written in response to a writing command, and the physical blocks of the spare area are used for substituting the physical blocks of the data area while executing the writing command. To perform a data accessing to the physical blocks storing data in an alternation approach for a host, the flash memory storage system may provide logical blocks (e.g. a plurality of logical blocks 210 in FIG. 1A) to the host for the data accessing. To be specific, the flash memory storage system maintains a logical-physical block mapping table for recording a mapping relation between the logical blocks and the physical blocks, wherein a logical block maps to a physical block grouped into the data area. Meanwhile, when the writing command is executed so that the physical blocks of the data area is exchanged to the physical blocks of the spare area, the flash memory storage system can update the logical-physical block mapping table for follow-up accessing.
FIG. 1A and FIG. 1B are schematic diagrams illustrating alternating of physical blocks of a flash memory according to a conventional technique.
Referring to FIG. 1A, if data is again written to a block written with data, an erase operation is first executed. However, in the flash memory, a writing unit (i.e. a page) is less than an erasing unit (i.e. a block), and therefore when the erase operation of the physical blocks is about to be executed, data in a valid page in the physical block has to be copied to another physical block, first. For example, if the host is about to write data into a logical block L of the configured logical blocks 210, the flash memory storage system then acquires that the logical block L is presently mapped to a physical block M in the data area 204 via the logical-physical block mapping table. Therefore, the flash memory storage system then updates data in the physical block M, wherein the flash memory storage system selects a physical block C from the spare area 206 to substitute the physical block M of the data area 204. However, when the new data is written into the physical block C, all of the valid data in the physical block M is not immediately moved to the physical block C to erase the physical block M. To be specific, the valid data (i.e. pages P0 and P1) in the physical block M before the address for writing the new data is copied to the physical block C (shown as (a) of FIG. 1B), and the new data (i.e. pages P2 and P3 of the physical block C) is written into the physical block C (shown as (b) of FIG. 1B). Now, the physical block C containing a part of the valid old data and the written new data is temporarily linked as a substitute physical block 208. This is because the valid data of the physical block M can be invalid in a next operation (for example, executing a writing command), and accordingly immediate movement of all of the valid data in the physical block M to the physical block C is unnecessary. In the present embodiment, a combination of the contents of the physical block M and the physical block C is the content of the mapped logical block L. Such a temporary mother-child block (i.e. the physical block M and the physical block C) relationship can be determined according to a size of a buffer memory in a controller. For example, there may be five child blocks.
Thereafter, the physical block M and the physical block C are only integrated into one block when the contents in the physical block M and the physical block C are to be actually combined, so as to improve a utilization efficiency of the blocks. For example, as shown in (c) of FIG. 2C, to integrate the blocks, the remaining valid data in the physical block M (i.e. pages P4˜PN) is coped to the physical block C, and then the physical block M is erased and linked to the spare area 206. Meanwhile, the physical block C is linked to the data area 204, and in the logical-physical block mapping table, the logical block L is changed for mapping to the physical block C. By now integration of these blocks is completed.
Since a programming specification of the flash memory requests that data has to be written in each physical block from a first page to a last page and each bit can only be programmed once (i.e. can only be programmed from “1” to “0”). Accordingly, once data is written into a page of a physical block, a physical block has to be selected from the spare area 206 (as shown in FIG. 1A) and the steps shown in FIG. 1B have to be repeated in order to update the data written into this page. Thereby, when the integration operation as illustrated in (c) of FIG. 1B is not yet performed to the physical blocks (i.e. the physical blocks are in the temporary state shown in (b) of FIG. 1B) and the newly moved data has to be updated (for example, pages P0˜P1 of FIG. 1B), the moved old data has to be moved again, which is referred to as a random writing mode. For example, a file allocation table (FAT) is usually used in a storage apparatus for managing a storage media, wherein the FAT data is accessed frequently. Accordingly, the random writing mode may be entered if the newly moved data is constantly renewed when the FAT table is accessed. In the random writing mode, the controller may sequentially write the data to be written into the pages of the physical block C, and movement of the valid data as shown in (a) of FIG. 1B is not performed, and only when the random writing mode is ended, is integration of the valid data performed, so as to avoid repeatedly executing the operations of FIG. 1A and FIG. 1B in the random writing mode.
Since a physical block in the flash memory maps to a logical block, when the logical blocks enters the random writing mode, the data to be written is only recorded in one physical block. However, the data frequently updated during the random writing mode is a small amount of data, and with progresses of a fabrication process of the flash memory, design volumes of the programming unit and the erasing unit become larger, so that utilization efficiency of the physical blocks during the random writing mode is decreased.